﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.Model.Domain;
using SMTC.WebCommon.Common;

public partial class ReportManagment_ReportView : BasePage
{
    public DateTime start
    {
        set
        {
            Session["start"] = value;
        }

        get
        {
            try
            {
               return  (DateTime)Session["start"];
            }
            catch
            {
                return new DateTime(1900, 1, 1);
            }
        }
    }

    public DateTime end
    {
        set
        {
            Session["end"] = value;
        }

        get
        {
            try
            {
                return (DateTime)Session["end"];
            }
            catch
            {
                return new DateTime(2999, 12, 31);
            }
        }
    }



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["start"] != null)
            {
                try
                {
                    this.start = DateTime.Parse(Request["start"].ToString());
                }
                catch
                {
                    this.start = new DateTime(1900, 1, 1);
                }
            }

            if (Request["end"] != null)
            {
                try
                {
                    this.end = DateTime.Parse(Request["end"].ToString());
                }
                catch
                {
                    this.end = new DateTime(2999, 12, 31);
                }
            }

            reportDataSource.SelectParameters.Add("PUVersion", Request["PUVersion"].ToString());
        }
    }

    protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ForcastTeepDomaincs item = e.Row.DataItem as ForcastTeepDomaincs;

        if (e.Row.RowType == DataControlRowType.DataRow && item != null)
        {
            double result = Math.Round((item.plan / double.Parse(item.capacity.ToString()) * 100), 2);
            Label lbl_ForcastTEEP = e.Row.FindControl("lbl_ForcastTEEP") as Label;
            lbl_ForcastTEEP.Text = result.ToString() + "%";

            if (result > 100)
            {
                e.Row.ToolTip = Resources.Resource.LackOfCapacity;//"本月能力不足";
                e.Row.BackColor = System.Drawing.Color.Pink;
            }
        }
    }
}